package com.ruoyi.loan.product.config;

import com.ruoyi.common.core.domain.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    //空指针异常
    @ExceptionHandler(value = NullPointerException.class)
    public R nullPointerExceptionHandler(NullPointerException ex) {
        ex.printStackTrace();
        return R.fail(500,"空指针异常");
    }

    //类型转换异常
    @ExceptionHandler(ClassCastException.class)
    public R classCastExceptionHandler(ClassCastException ex) {
        ex.printStackTrace();
        return R.fail(500,"类型转换异常");
    }

    //IO异常
    @ExceptionHandler(IOException.class)
    public R iOExceptionHandler(IOException ex) {
        ex.printStackTrace();
        return R.fail(500,"IOException异常");
    }

    @ExceptionHandler(Exception.class)
    public R ExceptionHandler(Exception ex) {
        ex.printStackTrace();
        return R.fail(500,"未知异常");
    }
}
